package com.ego.search.controller;

import com.ego.commons.pojo.EgoResult;
import com.ego.search.service.SearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SearchController {

    @Autowired
    private SearchService searchService;

    @RequestMapping("/search.html")
    public String search(String q, Model model,@RequestParam(defaultValue = "1") int page,@RequestParam(defaultValue = "20") int size ){



        Map<String,Object> searchMap = searchService.search(q,page,size);

        //共享数据
        model.addAllAttributes(searchMap);

        System.out.println("q = " + q);
        return "search";
    }




    @RequestMapping("/insert")
    @ResponseBody
    public int insert(@RequestParam  List<Long> ids){
        int result = searchService.insert(ids);
        System.out.println("result = " + result);
        return result;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public int delete(@RequestParam  List<String> ids){
        int result = searchService.delete(ids);
        return result;
    }
}
